package com.hnevc.trafficexpanedlistviewdemo.httppost;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.Random;

public class HttpThread extends Thread{
	private static final String TAG = "HttpThread";

	private Context context;
	private String url;
	private String jsonstring;
	private Handler handler;
	
	public HttpThread(Context context , Handler handler){
		this.context=context;
		//this.proDialog=proDialog;
		this.handler = handler;

	}
	
	@Override
	public void run(){
		/*HttpPostRequest post=new HttpPostRequest();
		int res=post.requestHttp(url, jsonstring);
		Log.e(TAG, "run: "+"****HttpThread中****url:"+url);
		Log.e(TAG, "run: "+"****HttpThread中****jsonstring:"+jsonstring);

		String webContent=post.getWebContext();
		System.out.println("***res:"+res);*/
		int res = 1;
		JSONArray jsonArray = new JSONArray();

		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("BusId",1);
			jsonObject.put("Distance",new Random(System.currentTimeMillis()).nextInt(12000));
			jsonArray.put(jsonObject);
			JSONObject jsonObject2 = new JSONObject();
			jsonObject2.put("BusId",2);
			jsonObject2.put("Distance",new Random(System.currentTimeMillis()).nextInt(11000));
			jsonArray.put(jsonObject2);

		} catch (JSONException e) {
			e.printStackTrace();
		}


		String webContent =jsonArray.toString()+'\n';
		if(res==1){
			Message msg = new Message();
			msg.what=res;
			msg.obj=webContent+"="+jsonstring;

			handler.sendMessage(msg);
		}	
		/******/
		else if(res==901){
			Message msg = new Message();
			msg.what=res;
			msg.obj="timeout!";
			handler.sendMessage(msg);
		}
		/******/
	}
	
	//activity界面传递的参数
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	
	public String getJsonstring() {
		return jsonstring;
	}

	public void setJsonstring(String jsonstring) {
		this.jsonstring = jsonstring;
	}
}

